package org.shoukaiseki.kakaroto;

import org.shoukaiseki.kakaroto.Interface.DictTypeEnumData;
import org.shoukaiseki.common.function.IGetter;
import org.shoukaiseki.common.utils.StringUtils;

import java.util.Map;

import static org.shoukaiseki.common.utils.BeanUtils.convertToFieldName;

/**
 * 增加条件
 **/
public class SksParamsExpression {

    Map<String, Object> sksParams;


    public SksParamsExpression(Map<String, Object> sksParams){
       this.sksParams = sksParams;
    }

    /**
     * 只显示为 0 的
     * @param fn
     * @return
     */
    public <T> SksParamsExpression equalsZero(IGetter<T> fn){
        addToSksParams(fn,"Equals",0);
        return this;
    }


    public <T> SksParamsExpression like(IGetter<T>  fn, Object obj){
        addToSksParams(fn,"Like",obj);
        return this;
    }

    public  <T> SksParamsExpression isNotNull(IGetter<T> fn){
        addToSksParams(fn,"IsNotNull",StringUtils.STRING_ONE);
        return this;
    }

    //为空字符
    public  <T> SksParamsExpression isEmpty(IGetter<T> fn){
        addToSksParams(fn,"IsEmpty",StringUtils.STRING_ONE);
        return this;
    }

    //不为空字符
    public  <T> SksParamsExpression notEmpty(IGetter<T> fn){
        addToSksParams(fn,"NotEmpty",StringUtils.STRING_ONE);
        return this;
    }

    public  <T> SksParamsExpression isNull(IGetter<T> fn){
        addToSksParams(fn,"IsNull",StringUtils.STRING_ONE);
        return this;
    }

    public <T> SksParamsExpression notLike(IGetter<T> fn, Object obj){
        addToSksParams(fn,"NotLike",obj);
        return this;
    }

    public <T> SksParamsExpression equals(IGetter<T> fn, Object obj){
        addToSksParams(fn,"Equals",obj);
        return this;
    }

    //字典里的值作为参数值
    public <T> SksParamsExpression equals(IGetter<T> fn, DictTypeEnumData obj){
        addToSksParams(fn,"Equals",obj.getValueString());
        return this;
    }


    public <T> SksParamsExpression not(IGetter<T> fn, Object obj){
        addToSksParams(fn,"Not",obj);
        return this;
    }

    public  <T> SksParamsExpression between(IGetter<T> fn, Object obj){
        addToSksParams(fn,"Between",obj);
        return this;
    }

    public  <T> SksParamsExpression lessThan(IGetter<T> fn, Object obj){
        addToSksParams(fn,"LessThan",obj);
        return this;
    }

    public  <T> SksParamsExpression before(IGetter<T> fn, Object obj){
        addToSksParams(fn,"Before",obj);
        return this;
    }

    public  <T> SksParamsExpression lessThanEqual(IGetter<T> fn, Object obj){
        addToSksParams(fn,"LessThanEqual",obj);
        return this;
    }

    public  <T> SksParamsExpression greaterThan(IGetter<T> fn, Object obj){
        addToSksParams(fn,"GreaterThan",obj);
        return this;
    }


    public  <T> SksParamsExpression after(IGetter<T> fn, Object obj){
        addToSksParams(fn,"After",obj);
        return this;
    }
    public  <T> SksParamsExpression greaterThanEqual(IGetter<T> fn, Object obj){
        addToSksParams(fn,"GreaterThanEqual",obj);
        return this;
    }


    public  <T> SksParamsExpression andTrue(IGetter<T> fn, Object obj){
        addToSksParams(fn,"AndTrue",obj);
        return this;
    }

    public  <T> SksParamsExpression andFalse(IGetter<T> fn, Object obj){
        addToSksParams(fn,"AndFalse",obj);
        return this;
    }

    public  <T> SksParamsExpression in(IGetter<T> fn, Object obj){
        addToSksParams(fn,"In",obj);
        return this;
    }

    public  <T> SksParamsExpression notIn(IGetter<T> fn, Object obj){
        addToSksParams(fn,"NotIn",obj);
        return this;
    }

    //添加自定义查询名
    public  <T> SksParamsExpression addCustomize(String paramName, Object obj){
        sksParams.put(paramName,obj);
        return this;
    }

    //app顶部查询默认搜索字段
    public  <T> SksParamsExpression addAppSearchValueListCustomize(Object obj){
        sksParams.put("appSearchValueListCustomize",obj);
        return this;
    }


    private <T> void addToSksParams(IGetter<T> fn,String jpaOption,Object obj){
        String s = convertToFieldName(fn);
        Object tmp=obj;
        if(obj!=null&&obj instanceof DictTypeEnumData){
            tmp=((DictTypeEnumData) obj).getValueString();
        }
        sksParams.put(s+jpaOption,tmp);
    }
}
